/**
 * for: MEP
 * at: VoucherScreen.java
 */
package com.vit.mep;

import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.component.LabelField;

import com.vit.bb.VitScreen;
import com.vit.mep.model.BankResponse;

/**
 * @author crodriguez
 * at date: 4:45:33 PM
 */
public class VoucherScreen extends VitScreen {

	protected BankResponse _bankResponse;
	
	protected MepApp _mepApp;
	
	
	private LabelField  _lblId;
	private LabelField  _lblAuth;
	private LabelField  _lblRef;
	private LabelField  _lblComercio;
	private LabelField  _lblResultCode;
	private LabelField  _lblResultMsg;
	private LabelField  _lblOtherMsg;
	
	private ButtonField _btnCancel;
	
	
	public VoucherScreen(MepApp mepApp){		
		_mepApp = mepApp;
		init();
	}
	
		
	
	
	private void init(){
		_lblId = new LabelField();
		_lblComercio = new LabelField();
		_lblAuth = new LabelField();
		_lblRef = new LabelField();		
		_lblResultCode  = new LabelField();
		_lblResultMsg = new LabelField();
		_lblOtherMsg = new LabelField();
		
		_btnCancel = new ButtonField("Terminado", ButtonField.CONSUME_CLICK);
		_btnCancel.setChangeListener(new CancelListener(this));
		
		_vfManager.add(_lblId);
		_vfManager.add(_lblComercio);
		_vfManager.add(_lblAuth);
		_vfManager.add(_lblRef);
		_vfManager.add(_lblResultCode);
		_vfManager.add(_lblResultMsg);
		_vfManager.add(_lblOtherMsg);
		_vfManager.add(_btnCancel);		
		
		add(_vfManager);
		
	}
	
	
	public void setBankResponse(BankResponse br){
		_bankResponse = br;
		repaint();
	}
	
	
	public void repaint(){		
		_lblId.setText("Id Transaccion: " + _bankResponse.getId());
		_lblComercio.setText("Comercio: " + _bankResponse.getComercio());
		_lblAuth.setText("Autorizacion: " + _bankResponse.getAuth());
		_lblRef.setText("Referencia: " + _bankResponse.getRef());		
		_lblResultCode.setText("Respuesta: " + _bankResponse.getResultCode());
		_lblResultMsg.setText("Mensaje: " + _bankResponse.getResultMsg());
		_lblOtherMsg.setText("Otros: " + _bankResponse.getOtherMsg());
		
	}
	
	
	class CancelListener implements FieldChangeListener{
		private VoucherScreen vs;
		CancelListener(VoucherScreen vs){
			this.vs = vs;
		}
		public void fieldChanged(Field field, int context) {				
			_mepApp.init(vs);
		}		
	}//CancelListener
	
}//class